"use strict";

const Sequelize = require("sequelize");
const env = require("./env");
const sequelize = new Sequelize(
  env.DATABASE_NAME,
  env.DATABASE_USERNAME,
  env.DATABASE_PASSWORD,
  {
    host: env.DATABASE_HOST,
    port: env.DATABASE_PORT,
    dialect: env.DATABASE_DIALECT,
    define: {
      underscored: true
    }
  }
);

// Connect all the models/tables in the database to a db object,
//so everything is accessible via one object
const db = {};

db.Sequelize = Sequelize;
db.sequelize = sequelize;

db.aiLabTask = sequelize.define(
  "ai_lab_task",
  {
    id: {
      type: Sequelize.BIGINT,
      autoIncrement: true,
      primaryKey: true
    },
    uid: {
      type: Sequelize.TEXT,
      required: true
    },
    state: {
      type: Sequelize.TEXT,
      required: true
    },
    input: {
      type: Sequelize.JSONB,
      allowNull: true
    },
    output: {
      type: Sequelize.JSONB,
      allowNull: true
    },
    create_at: Sequelize.DATE
  },
  {
    paranoid: true,
    underscored: true,
    freezeTableName: true,
    timestamps: false
  }
);

module.exports = db;
